<template>
	<view>
		<map id="myMap" style="width: 100%; height: 300px;" :longitude="longitude" :latitude="latitude"
			:markers="covers" scale="3" :polyline="polylne"></map>

		<button type="primary" @click="confirm()">确认收货</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderDetailId: "",
				logistics: {},
				longitude: "",
				latitude: "",
				covers: [{
					latitude: 39.909,
					longitude: 116.39742,
					iconPath: "../../static/位置.png"
				}, {
					latitude: 39.90,
					longitude: 116.39,
					iconPath: "../../static/位置 (2).png"
				}],
				polylne: [{
					points: [{
							latitude: 39.904989,
							longitude: 116.405285
						},
						{
							latitude: 39.907127,
							longitude: 116.404465
						}
					],
					color: '#FF0000DD',
					width: 2,
					dottedLine: true
				}]
			}
		},
		methods: {
			confirm() {
				uni.request({
					url: 'api/order-server/confirmOrder',
					header: {
						"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ6eU1hbmFnZSI6eyJpZCI6IjE4MjA3NzkzMTgxODg1NzY3NjgiLCJtYW5hZ2VBY2NvdW50IjoiY2oiLCJtYW5hZ2VOaWNrTmFtZSI6ImNqIn19.AI1W3jxpA1T1k438YI8weWTw_51jKU2uUQAjKKJ3Rig"
					},
					data: {
						"orderDetailId": this.orderDetailId,
					},
					success: (res) => {
						if (res.data.code == 200) {
							uni.showToast({
								title: '收货成功',
								icon: 'success',
								duration: 2000
							});
						}
					},
				})
				
			},
			queryLogisticsByOrderDetailId() {
				uni.request({
					url: 'api/order-server/queryLogisticsByOrderDetailId',
					header: {
						"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ6eU1hbmFnZSI6eyJpZCI6IjE4MjA3NzkzMTgxODg1NzY3NjgiLCJtYW5hZ2VBY2NvdW50IjoiY2oiLCJtYW5hZ2VOaWNrTmFtZSI6ImNqIn19.AI1W3jxpA1T1k438YI8weWTw_51jKU2uUQAjKKJ3Rig"
					},
					data: {
						"orderDetailId": this.orderDetailId,
					},
					success: (res) => {
						if (res.data.code == 200) {
							this.logistics = res.data.data;
							var fromWhere = res.data.data.fromWhere;
							var toWhere = res.data.data.toWhere;
							var from = fromWhere.split(",");

							var to = toWhere.split(",");
							console.log(to)
							this.latitude = to[1];
							this.longitude = to[0];
							this.covers[0].latitude = from[1];
							this.covers[0].longitude = from[0];
							this.covers[1].latitude = to[1];
							this.covers[1].longitude = to[0];
							this.polylne[0].points[0].latitude = from[1];
							this.polylne[0].points[0].longitude = from[0];
							this.polylne[0].points[1].latitude = to[1];
							this.polylne[0].points[1].longitude = to[0];

							// this.covers.push(fromW);
							// this.covers.push(toW);

							// this.from.push(fromW);
							// this.to.push(toW)
						}
					},
				})
			}
		},
		onLoad(e) {
			this.orderDetailId = e.orderDetailId
			this.queryLogisticsByOrderDetailId()
			this.mapCtx = uni.createMapContext('myMap', this); // 创建地图上下文
		}
	}
</script>

<style>

</style>